package reflect;/*
 *@ 代阳敲的专属代码
 **/

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class TestRefilect {
    public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException, NoSuchFieldException {
//        Class<?>clazz = Class.forName("reflect.User");
//        Method method = clazz.getDeclaredMethod("publicMethod");
//        method.invoke(clazz.getDeclaredConstructor().newInstance());

//        Class<?>clazz2 =Class.forName("reflect.User");
//        Method method1=clazz2.getDeclaredMethod("privateMethod");
//        method1.setAccessible(true);
//        method1.invoke(clazz2.getDeclaredConstructor().newInstance());

//        Class<?> clazz3=Class.forName("reflect.User");
//        Method method2=clazz3.getDeclaredMethod("staticMethod");
//        method2.invoke(clazz3.getDeclaredConstructor().newInstance());

        Class<?> clazz4=Class.forName("reflect.User");
        Field field=clazz4.getDeclaredField("name");
        String name=(String) field.get(clazz4.getDeclaredConstructor().newInstance());
        System.out.println(name);

        Class<?> clazz5=Class.forName("reflect.User");
        Field field1=clazz5.getDeclaredField("age");
        field1.setAccessible(true);
        int age=(int) field1.get(clazz5.getDeclaredConstructor().newInstance());
        System.out.println(age);
    }
}
